home *** CD-ROM | disk | FTP | other *** search
- Path: dfw.dfw.net!not-for-mail
- From: ftlgeuse@dfw.dfw.net (Azazel Diabolus (aka Fetelgeuse))
- Newsgroups: comp.lang.c
- Subject: RE: Hiding a password
- Date: 27 Mar 1996 18:13:50 GMT
- Organization: DFW Internet Services - DFWNet: 800-2-DFWNet
- Message-ID: <4jc0gu$crg@fnord.dfw.net>
- NNTP-Posting-Host: dfw.dfw.net
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) wrote:
-
- >In article <4hehmd$1fr@fnord.dfw.net>
- >ftlgeuse@dfw.dfw.net (Fetelgeuse) writes:
- >
- ><snip>
- >F: I wrote a function to do precisely the same thing. I made a function
- >F: something like:
- >F: char * GetString_NoEcho()
- >F: {
- >F: char *temp;
- >F: int i=1;
- >F: while(temp[i-1]!=13) {
- >F: temp[i-1]=getch();
- >F: i++;
- >F: }
- >F: temp[i]=0;
- >F: }
- >
- >Please test your solutions before you post them. I tried the following
- >program:
- >
- <CODE SIMILAR TO ABOVE REMOVED FOR BREVITY>
- >
- >When I tried to compile it, I get
- >
- >j.c:3: warning: function declaration isn't a prototype
- >j.c: In function `GetString_NoEcho':
- >j.c:7: warning: implicit declaration of function `getch'
- >j.c:4: warning: `temp' might be used uninitialized in this function
- >j.c:11: warning: control reaches end of non-void function
- >j.c: In function `main':
- >j.c:13: warning: `pwd' might be used uninitialized in this function
- >j.c:4: warning: `temp' might be used uninitialized in this function
- >ld: Undefined symbol
- > _getch
- >
- >and I get no executable.
- >
- >Can you help me? Any idea what I am doing wrong? Should I change the
- >i-1 to i*=+5 to get it to work?
- >
- >If you haven't, please remember that when you post something that is
- >wrong, you confuse a lot of other people. If you are merely trying to
- >learn, please ask questions: do not pretend to know the answer when
- >you don't.
- >
- >Cheers
- >Tanmoy
- >--
- >
-
- OK, Tanmoy, there is no need to be such a smart-ass. The code I posted was
- a mere "snippet" to give the original poster and idea of the "theory" of
- my suggestion. I openly admitted that the code verbatim probably would not
- do the trick which is why I explained what it was doing. It is not up to me
- to ensure that each reader knows how to properly prototype his/her functions,
- or knows which header files to include for a given function (i.e. getch())
-
- Also, the compiler the reader chooses is obviously going to make a difference
- so I will remember to include which compiler I succesfully used with any
- future code references to prevent the onslaught of nitpicking egoists from
- flooding my mailbox with things like "that won't work! Jeez you're dumb."
-
- Anyone with at least half a brain would have read on after the code and seen
- where I said that I typed it quickly and there are probably mistakes, it was
- just there to give the reader an IDEA so they could write there own code. But
- for everyone who did not like my advice to the original poster, here is the
- code I was describing that will work if it is typed in EXACTLY as I have
- typed it. Also, I compiled it with Borland's Turbo C/C++ v3.0 for DOS.
-
- To save the typing of those who wish to pick apart my friendly advice:
- This code is not a tutorial in encryption or security, it is just meant to
- show the original poster a way he can get input from the keyboard without
- having it echoed to the screen! (I wrote it merely because I did not like
- the limitiation of my compilers version of a function in conio.h called
- getpass() which limits the input to 8 characters. I also realize that the
- buffer could overflow causing problems but on my computer using this function
- I have input 300 characters without a problem- I haven't tried any more
- than that)
-
- Here it is, like it or not:
-
- /*-----------------------BEGIN CODE-----------------*/
-
- #include<stdio.h>
- #include<conio.h>
-
- char *getstring_noecho()
- {
- char *string;
- int i=0;
- _setcursortype(0);
- while(string[i-1]!=13) {
- string[i++]=getch();
- }
- string[i-1]=NULL;
- return(string);
- }
-
- void main()
- {
- char *password;
- printf("Enter password:");
- password=getstring_noecho();
- printf("%s",password);
- }
-
- /*-----------------------END CODE-----------------*/
-
- If you want to rag on this go ahead but remember that it was only meant as
- a nice gesture to the person who had asked for a way to get input from the
- keyboard without having it echoed to the screen; I gave him a way. That
- is the only thing this code is meant to do so for everyone who sits around
- waiting to harp on someones code they dislike - get a life; if you don't
- like someone's advice to someone else, give better advice or shut up!
-
- Oh, and Tanmoy, don't pretend to have a clue when you don't.
-
- Fetelgeuse.
-
-